/*
 * @Author: your name
 * @Date: 2021-10-18 17:04:01
 * @LastEditTime: 2021-10-18 17:04:30
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \admin-plus-main\src\utils\aes.js
 */
// import Vue from 'vue'
import CryptoJS from 'crypto-js'
const keyM = 'QAZwsx123456789!@#$%^&*(QAZwsx123456789!@#$%^&*(' // QAZwsx123456789!@#$%^&*(
const keyMToken = 'QAZwsx123456789!@#$%^&*('
export default {
  keyM,
  keyMToken,
  /**
   * 加密
   * @param word
   * @returns {*}
   */
  encrypt(word, keyM) {
    var key = CryptoJS.enc.Utf8.parse(keyM)
    var srcs = CryptoJS.enc.Utf8.parse(word)
    var encrypted = CryptoJS.AES.encrypt(srcs, key, {
      mode: CryptoJS.mode.ECB,
      padding: CryptoJS.pad.Pkcs7,
    })
    return encrypted.toString()
  },

  /**
   * 解密
   * @param word
   * @returns {*}
   */
  decrypt(word, keyM) {
    var key = CryptoJS.enc.Utf8.parse(keyM)
    var decrypt = CryptoJS.AES.decrypt(word, key, {
      mode: CryptoJS.mode.ECB,
      padding: CryptoJS.pad.Pkcs7,
    })
    return CryptoJS.enc.Utf8.stringify(decrypt).toString()
  },

  rightPad(str, size, padStr) {
    if (str === null) {
      return null
    } else {
      var padLen = padStr.length
      var strLen = str.length
      var pads = size - strLen
      if (pads <= 0) {
        return str
      } else if (padLen === 1 && pads <= 8192) {
        return this.rightPad(str, size, padStr.charAt(0))
      } else if (pads === padLen) {
        return str.concat(padStr)
      } else if (pads < padLen) {
        return str.concat(padStr.substring(0, pads))
      } else {
        return str
      }
    }
  },
}
